﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;

namespace Wala.Connection.Objects.Authen
{
    public class UserLogin
    {
        #region //--------- Private Fields -----------//

        private uint _id;        
        private string _token;       
        
        #endregion

        #region //--------- CLR Properties -----------//

        public uint Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public string Token
        {
            get { return _token; }
            set { _token = value; }
        }

        #endregion

        #region //---------- Puclic Constructor -----------//

        public UserLogin()
        {
            _id = 0;
            _token = "";
        }

        public UserLogin(uint _id, string _token)
        {
            this._token = _token;
            this._id = _id;
        }

        #endregion

        #region //----------- Public Methods ----------//

        public static UserLogin FromJson(string json)
        {
            try
            {
                JObject jObject = JObject.Parse(json);
                uint id = (uint)jObject["id"];
                string token = (string)jObject["token"];

                return new UserLogin(id,token);
            }
            catch (Exception ex)
            {
                return new UserLogin();
            }
        }

        #endregion
    }
}
